package com.tencent.tws.watchfacelib;

import android.content.Context;
import android.content.Intent;
import android.graphics.DrawFilter;
import android.graphics.PaintFlagsDrawFilter;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.tencent.tws.watchfaceimpl.IWatchface;
import com.tencent.tws.watchfacelib.interfaces.IWatchDoze;
import com.tencent.tws.watchfacelib.interfaces.IWatchLifecycle;
import com.tencent.tws.watchfacelib.manager.BroadcastReceiverCommonService;
import com.tencent.tws.watchfacelib.manager.BroadcastReceiverCommonService.ResponseListener;
import java.util.Calendar;
import java.util.Set;
import java.util.TimeZone;

public abstract class AbsWatchView
  extends View
  implements IWatchLifecycle, IWatchDoze
{
  protected static final int DEFAULT_REFRESH_INTERVAL = 60;
  protected static final int MSG_REFRESH = 1;
  private static final String TAG = AbsWatchView.class.getSimpleName();
  private final int DEF_FLAG = 30;
  protected final Calendar calendar = Calendar.getInstance();
  private IWatchface.ICallbackFinished callback;
  private final BroadcastReceiverCommonService commonService = new BroadcastReceiverCommonService(getContext());
  protected int curHour24;
  protected float curHourAngle;
  protected int curMillisecond;
  protected int curMinute;
  protected float curMinuteAngle;
  protected int curSecond;
  protected float curSecondAngle;
  private int customFlag;
  private ResponseListener customListener;
  private Set<String> customOtherAction;
  private DrawFilter filter;
  private final Handler handler = new Handler()
  {
    public void handleMessage(Message paramAnonymousMessage)
    {
      super.handleMessage(paramAnonymousMessage);
//      switch (paramAnonymousMessage.what)
//      {
//      default:
//        return;
//      }
      AbsWatchView.this.updateCalendar();
      AbsWatchView.this.onTimeRefreshing();
      AbsWatchView.this.invalidate();
      AbsWatchView.this.handler.sendEmptyMessageDelayed(1, AbsWatchView.this.refreshInterval);
    }
  };
  private boolean isDoze = false;
  private int refreshInterval = 60;
  
  public AbsWatchView(Context paramContext)
  {
    this(paramContext, null);
  }
  
  public AbsWatchView(Context paramContext, AttributeSet paramAttributeSet)
  {
    this(paramContext, paramAttributeSet, 0);
  }
  
  public AbsWatchView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
  }
  
  private void registerListener()
  {
    this.commonService.register(this.customFlag | 0x1E, this.customOtherAction, new ResponseListener()
    {
      public void onCustomActionFired(Context paramAnonymousContext, Intent paramAnonymousIntent)
      {
        Log.d(AbsWatchView.TAG, "onCustomActionFired");
        if (AbsWatchView.this.customListener != null) {
          AbsWatchView.this.customListener.onCustomActionFired(paramAnonymousContext, paramAnonymousIntent);
        }
      }
      
      public void onDateChanged()
      {
        Log.d(AbsWatchView.TAG, "onDateChanged");
        if (AbsWatchView.this.customListener != null) {
          AbsWatchView.this.customListener.onDateChanged();
        }
      }
      
      public void onReceiveCurrentStep(Object paramAnonymousObject, int paramAnonymousInt)
      {
        Log.d(AbsWatchView.TAG, "onReceiveCurrentStep");
        if (AbsWatchView.this.customListener != null) {
          AbsWatchView.this.customListener.onReceiveCurrentStep(paramAnonymousObject, paramAnonymousInt);
        }
      }
      
      public void onReceiveGoalStep(Object paramAnonymousObject, int paramAnonymousInt)
      {
        Log.d(AbsWatchView.TAG, "onReceiveGoalStep");
        if (AbsWatchView.this.customListener != null) {
          AbsWatchView.this.customListener.onReceiveGoalStep(paramAnonymousObject, paramAnonymousInt);
        }
      }
      
      public void onReceiveWeatherInfo(Object paramAnonymousObject1, Object paramAnonymousObject2)
      {
        Log.d(AbsWatchView.TAG, "onReceiveWeatherInfo");
        if (AbsWatchView.this.customListener != null) {
          AbsWatchView.this.customListener.onReceiveWeatherInfo(paramAnonymousObject1, paramAnonymousObject2);
        }
      }
      
      public void onTimeChanged()
      {
        Log.d(AbsWatchView.TAG, "onTimeChanged");
        if (AbsWatchView.this.customListener != null) {
          AbsWatchView.this.customListener.onTimeChanged();
        }
      }
      
      public void onTimeTicked()
      {
        Log.d(AbsWatchView.TAG, "onTimeTicked");
        if (AbsWatchView.this.customListener != null) {
          AbsWatchView.this.customListener.onTimeTicked();
        }
      }
      
      public void onTimeZoneChanged()
      {
        Log.d(AbsWatchView.TAG, "onTimeZoneChanged");
        AbsWatchView.this.calendar.setTimeZone(TimeZone.getDefault());
        if (AbsWatchView.this.customListener != null) {
          AbsWatchView.this.customListener.onTimeZoneChanged();
        }
      }
    });
  }
  
  public final void dozeEntering(IWatchface.ICallbackFinished paramICallbackFinished)
  {
    this.isDoze = true;
    this.callback = paramICallbackFinished;
    this.handler.removeMessages(1);
    onDozeEntering();
    updateCalendar();
    invalidate();
  }
  
  public final void dozeExiting(IWatchface.ICallbackFinished paramICallbackFinished)
  {
    this.isDoze = false;
    this.callback = paramICallbackFinished;
    onDozeExiting();
    this.handler.removeMessages(1);
    this.handler.sendEmptyMessage(1);
    updateCalendar();
    invalidate();
  }
  
  protected final void dozeInvalidated()
  {
    if (this.callback != null)
    {
      this.callback.onCallbackFinished();
      this.callback = null;
    }
  }
  
  public final void dozeUpdate(IWatchface.ICallbackFinished paramICallbackFinished)
  {
    this.callback = paramICallbackFinished;
    onDozeUpdate();
    updateCalendar();
    invalidate();
  }
  
  protected DrawFilter getAntiAliasFilter()
  {
    if (this.filter == null) {
      this.filter = new PaintFlagsDrawFilter(0, 3);
    }
    return this.filter;
  }
  
  protected final boolean isDoze()
  {
    return this.isDoze;
  }
  
  protected void onDozeEntering() {}
  
  protected void onDozeExiting() {}
  
  protected void onDozeUpdate() {}
  
  protected void onPause() {}
  
  protected void onResume() {}
  
  protected void onStart() {}
  
  protected void onStop() {}
  
  protected void onTimeRefreshing() {}
  
  public final void pause()
  {
    onPause();
    this.handler.removeMessages(1);
  }
  
  protected final void registerBroadcastReceiver(int paramInt, Set<String> paramSet, ResponseListener paramResponseListener)
  {
    this.customFlag = paramInt;
    this.customOtherAction = paramSet;
    this.customListener = paramResponseListener;
    registerListener();
  }
  
  protected void resetCalendar()
  {
    this.calendar.setTimeInMillis(System.currentTimeMillis());
    this.calendar.setTimeZone(TimeZone.getDefault());
  }
  
  public final void resume()
  {
    resetCalendar();
    onResume();
    this.handler.removeMessages(1);
    this.handler.sendEmptyMessage(1);
  }
  
  protected void setRefreshInterval(int paramInt)
  {
    this.refreshInterval = paramInt;
  }
  
  public final void start()
  {
    this.isDoze = false;
    registerListener();
    onStart();
  }
  
  public final void stop()
  {
    this.commonService.unregister();
    onStop();
  }
  
  protected void updateCalendar()
  {
    this.calendar.setTimeInMillis(System.currentTimeMillis());
    this.curHour24 = this.calendar.get(Calendar.HOUR_OF_DAY);
    this.curMinute = this.calendar.get(Calendar.MINUTE);
    this.curSecond = this.calendar.get(Calendar.SECOND);
    this.curMillisecond = this.calendar.get(Calendar.MILLISECOND);
    this.curHourAngle = ((this.curHour24 % 12 + this.curMinute / 60.0F + this.curSecond / 3600.0F) * 30.0F);
    this.curMinuteAngle = ((this.curMinute + this.curSecond / 60.0F) * 6.0F);
    this.curSecondAngle = ((this.curSecond + this.curMillisecond / 1000.0F) * 6.0F);
  }
}


/* Location:              G:\zyl\ylwork\Android\Android_Decode\apk2java\apktool2.1.0\WatchFaceSports\classes-dex2jar.jar!\com\tencent\tws\watchfacelib\AbsWatchView.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */